<!DOCTYPE html>
<html>
<head>
    <title>video form</title>
    <#include "/header.html">
</head>
<body class="bg-white">
<div id="appMain">
    <form class="layui-form layuimini-form" action="" lay-filter="dataForm">
        <div class="layui-form-item">
            <label class="layui-form-label">房间号</label>
            <div class="layui-input-block">
                <input type="text" name="rmid" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">楼层</label>
            <div class="layui-input-block">
                <input type="text" name="floor" value="" class="layui-input">
            </div>
        </div>
      <div class="layui-form-item">
            <label class="layui-form-label">房间类型</label>
            <div class="layui-input-block">
                <select id="roomst" name="roomst" lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">面积(㎡)</label>
            <div class="layui-input-block">
                <input type="text" name="mj" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">预定状态</label>
            <div class="layui-input-block">
                <input type="radio" name="reserve" value="已预订" title="已预订">
                <input type="radio" name="reserve" value="未预定" title="未预定">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">使用状态</label>
            <div class="layui-input-block">
                <input type="radio" name="useState" value="使用中" title="使用中">
                <input type="radio" name="useState" value="未使用" title="未使用">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input type="text" name="remarks" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" id="commitBtn" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    layui.use(['form', 'laydate', 'upload'], function () {
        var form = layui.form,
        upload = layui.upload,
            $ = layui.$;
        var laydate = layui.laydate;
        var keywords = [];
        var _parent = parent;


      //获取类型select
  	  $.ajax({
  			url:serverUrl('kaijie/roomsortinfn/listRoomSortInfn'),
  			type:"get",
  			dataType:"",
  			success:function(btn){
  			    //console.log(btn.data[0].rsid);
  		          var select = $("#roomst");
  			      	for (var j = 0; j < btn.count; j++) {
  				      	  select.append("<option value='"+btn.data[j].rsid+"'>"+btn.data[j].roomst+"</option>");
  			  		}
  		          layui.form.render("select");
  			},
  			error:function(){
  				console.log("类型获取失败");
  			}
  		})

        $(document).ready(function () {
            if (parent.formDataId > 0) {
                $.ajax({
                    type: "POST",
                    url: serverUrl('kaijie/roominfn/info/' + parent.formDataId),
                    data: {},
                    dataType: "json",
                    success: function (result) {
                        if (result.code === 0) {
                            form.val('dataForm', result.roomInfn);
                        }
                    }
                });
            }
        });
        var submitForm = function () {
            var params = form.val('dataForm');
            params['id'] = _parent.formDataId || null;

            var method = _parent.formDataId > 0 ? 'update' : 'save';
            submitFormData('kaijie/roominfn/'+method, params);
        };

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#uploadBtn'
            ,url: serverUrl('oss/file/upload')
            ,auto: false
            ,choose: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#uploadPreview').attr('src', result); //base64
                });
            }
            ,done: function(res){
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                form.val('dataForm', {'image': res.url});
                submitForm();
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            submitForm();
            return false;
        });

    });
</script>
</body>
</html>